<?php

	// NOTHING ABOVE HERE !!!
	
	// here we need to get the user modes.. and if, we have only one user mode, we set that as the default automagically.
	
	// if there is no mode.. just display the page sans the user modes
	
	$modes = modesForUserId($authInfo->uid, $db);
	
?>
<div id="cms_contentIndex">
	<table width="645" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td valign="top" width="560" class="body2-8"> <span class="contentheading"><br/>
                
<!-- DONT CHANGE BETWEEN HERE -->
            <div>
<?php


	
	foreach($modes as $mode){
		//$mode->groupname
		
		$labelLocation="cms";
		if (!in_array( $mode->modecode, array("intranet","cms","mailout","site","admin","",null))){
			$labelLocation = "site";
		}
	
		$u = $_SERVER['PHP_SELF'] . "?viewModeSent="  . $mode->modemask . "&fileNo=13";
		print <<< EOD
			<a href="$u" /><img alt="$mode->groupname" src="/$labelLocation/images/mode_icon_$mode->modecode.gif" align="top" /></a>
EOD;

	}
	
	
	$gid = groupForMode($viewMode, $db);
	$mode = groupObjectForMode($viewMode, $db);//echo "Mode = <pre>";print_r($mode);echo "</pre>";
	
	$cmsDocument->flush();
	$cmsDocument->addDocumentType("docCMSWebPge");
	$cmsDocument->addConstraint("shortdescription", $gid); //Site Group
	$cmsDocument->resetIterator();
	$row = $cmsDocument->nextDocument();
?>

           </div>
<!-- and HERE -->                
              <br />
              <!--Welcome 
              to the Gravitate CMS.</span><br> 
              <br>
              This is the management console for the website:<br>
              <br />
              <a href="<?= CMS_HTTP_HOST?>" target="_blank" class="cms_contentlinks"><?= TITLE ?></a><br /> 
              <br />
              Here you can add, edit or delete records from your website database. 
              Any changes you make will be instantly reflected on the live site.<br> 
              <br> <b>Important Note:</b> After you have made changes to the CMS, 
              please check the 'live' site to ensure they appear as you wish them 
              to.<br> <br>
              To make changes, use the menu on the left hand side of the page, 
              or if you know the record ID, you can enter it into the box below 
            and chose the appropriate action. -->
              <?= $row->content; ?>
              </td>
          </tr>
          <?
          ?>
          
          <tr>
          	  <td>
          	  	<?

$cmsDocument->flush();
$cmsDocument->addDocumentType("docCMSQuLink");
$cmsDocument->addConstraint("categorycode", $gid); //Site
$cmsDocument->addSort("content + 0");
$cmsDocument->resetIterator();
if ($cmsDocument->totalDocuments()) {
?>
<br /><br />
<p><img src="/cms/images/quick_links.gif" alt="Quick Links" width="645" height="22" /></p>

    <table width="90%" border="0" align="center" cellpadding="0" cellspacing="5">
<?
}
$cell = 1;
while ($row = $cmsDocument->nextDocument()) {
	if ($cell == 1) {
		echo "<tr>\n";
		echo "  <td width='50%'>\n";
		echo "    <a href='".$row->shortdescription."'>".$row->title."</a>\n";
		echo "  </td>\n";
		$cell++;
	}
	else {
		echo "  <td width='50%'>\n";
		echo "    <a href='".$row->shortdescription."'>".$row->title."</a>\n";
		echo "  </td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='5' colspan='2' background='/cms/images/spacer.gif'></td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='1' colspan='2' background='/cms/images/cnt_divider.gif'></td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='5' colspan='2' background='/cms/images/spacer.gif'></td>\n";
		echo "</tr>\n";
		$cell--;
	}
}
if ($cmsDocument->totalDocuments()) {
	if ($cell == 2) {
		echo "  <td>&nbsp;</td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='5' colspan='2' background='/cms/images/spacer.gif'></td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='1' colspan='2' background='/cms/images/cnt_divider.gif'></td>\n";
		echo "</tr>\n";
		echo "<tr>\n";
		echo "  <td height='5' colspan='2' background='/cms/images/spacer.gif'></td>\n";
		echo "</tr>\n";
	}
?>
    </table>
<?
}
?>
    <br />
    <br />
    <br />

    <img src="/cms/images/for_assistance.gif" alt="For Assistance Links" width="645" height="22" /><br />  
<br />
Please contact Gravitate Ltd. Email <a href="mailto:support@gravitate.co.nz">support@gravitate.co.nz</a> or Phone +64 9 309 5015
          	  </td>
          </tr>
	  </table>
</div>